package com.caigp.cookbook2.adapter;

import android.content.res.Resources;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.caigp.cookbook2.R;
import com.caigp.cookbook2.bean.Menu;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class MenuLeftAdapter extends BaseQuickAdapter<Menu, BaseViewHolder> {

    private int itemPosition;

    public MenuLeftAdapter(int layoutResId, @Nullable List<Menu> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, Menu item) {
        helper.setText(R.id.text_view, item.getName());
        int layoutPosition = helper.getLayoutPosition();
        if (layoutPosition == itemPosition) {
            TextView textView = helper.itemView.findViewById(R.id.text_view);
            textView.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
        } else {
            TextView textView = helper.itemView.findViewById(R.id.text_view);
            textView.setTextColor(Color.BLACK);
        }
    }

    public void setItemPosition(int itemPosition) {
        this.itemPosition = itemPosition;
        notifyDataSetChanged();
    }
}
